public class demo12 {
    public int function(int num)
    {
        int ret = 0;
        while(num!=0)
        {
            int tmp = num%10;
            num = num/10;
            ret += tmp*tmp;
        }
        return ret;
    }
    public boolean isHappy(int n) {
        if(n==1||n==7)
            return true;
        int num = function(n);
        while(num != n)
        {
            n = function(n);
            num = function(function(num));
            if(num == 1)
                return true;
        }
        return false;
    }
}
